#!/usr/bin/env python
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (c) 2010 by Derek Anderson
#

import datetime, json, os, sqlite3, sys, textwrap, threading, time, traceback, uuid

import sqlparse

try:
  import pygtk
  pygtk.require("2.0")
  import gtk
  import gtk.glade
  import gtksourceview2
  import gobject, gnome
  import pango
except:
  traceback.print_exc()
  sys.exit(1)

from util import *
import gui_main



# this doesn't work
def fix_sqlite3_for_with():
  class O():
    pass
  old_connect = sqlite3.connect
  def new_connect(*args,**kwargs):
    conn = old_connect(*args,**kwargs)
    print 'conn', conn
    old_cursor = conn.cursor
    def new_cursor(*args,**kwargs):
      cur = old_cursor(*args,**kwargs)
      new_cur = O()
      for a in dir(cur):
        if a in ('__class__',): continue
        #print a, getattr(cur,a)
        setattr(new_cur, a, getattr(cur,a))
      new_cur.__exit__ = new_cur.close
      print 'new_cur.__exit__', new_cur.__exit__
      return new_cur
    new_conn = O()
    for a in dir(conn):
      if a in ('__class__',): continue
      #print a, getattr(conn,a)
      setattr(new_conn, a, getattr(conn,a))
    new_conn.cursor = new_cursor
    return new_conn
  sqlite3.connect = new_connect
  print 'fix_sqlite3_for_with done'
#fix_sqlite3_for_with()





if __name__=='__main__':
    gnome.init( PROGRAM_NAME, PROGRAM_VERSION )
    gobject.threads_init()
    gtk.gdk.threads_init()
    global main
    main = gui_main.DeSQL()
    #main.new_conn()
    gtk.main()
    

